package com.scs.application.modules.sys.adapter;

import com.scs.application.modules.sys.properties.SystemProperties;
import com.scs.application.modules.sys.service.DataViewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Description:视图服务适配器
 */
@Component
public class DataViewAdapter {
    @Autowired
    private SystemProperties systemProperties;

    private List<DataViewService> dataViewServices;

    @Autowired
    private void setDataViewServices(List<DataViewService> dataViewServices) {
        this.dataViewServices = dataViewServices;
    }

    /**
     * 获取当前项目的DataView实现类
     * @return
     */
    public DataViewService getDataViewService() {
        DataViewService dataViewService = null;
        for(DataViewService dvService : dataViewServices) {
            if (dvService.isSupport(systemProperties.getFlagProject())) {
                dataViewService = dvService;
                break;
            }
        }
        return dataViewService;
    }

    /**
     * 根据类型获取DataView实现类
     * @param flagProject
     * @return
     */
    public DataViewService getDataViewService(Boolean flagProject) {
        DataViewService dataViewService = null;
        for(DataViewService dvService : dataViewServices) {
            if (dvService.isSupport(flagProject)) {
                dataViewService = dvService;
                break;
            }
        }
        return dataViewService;
    }
}
